package com.zz;

import com.zz.config.JDBCUtil;
import org.junit.Test;

import java.sql.Connection;
import java.util.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class TestMain {
    public static void main(String[] args) throws SQLException {
        Connection con = JDBCUtil.getCon();
        String sql = "insert into actor values(?,?,?,?,?)";
        PreparedStatement pre = JDBCUtil.pre(con, sql);
        pre.setObject(1,null);
        pre.setObject(2, "张三");
        pre.setObject(3, "男");
        pre.setObject(4, new Date());
        pre.setObject(5, "15631846420");

        int i = JDBCUtil.preExe(pre);
        System.out.println("i = " + i);

        JDBCUtil.close(pre,con);
    }

    @Test
    public void fa1() throws SQLException {
        Connection con = JDBCUtil.getCon();
        String sql = "insert into actor values(?,?,?,?,?)";
        PreparedStatement pre = JDBCUtil.pre(con, sql);
        pre.setObject(1,null);
        pre.setObject(2, "王五");
        pre.setObject(3, "女");
        pre.setObject(4, new Date());
        pre.setObject(5, "15631823420");

        int i = JDBCUtil.preExe(pre);
        System.out.println("i = " + i);

        JDBCUtil.close(pre,con);
    }

    @Test
    public void fa2() throws SQLException {
        Connection con = JDBCUtil.getCon();
        String sql = "update actor set phone=? where id = ?";
        PreparedStatement pre = JDBCUtil.pre(con, sql);
        pre.setObject(1,"15631823582");
        pre.setObject(2, "2");

        int i = JDBCUtil.preExe(pre);
        System.out.println("i = " + i);

        JDBCUtil.close(pre,con);
    }

    @Test
    public void fa3() throws SQLException {
        Connection con = JDBCUtil.getCon();
        String sql = "delete from actor where id = ?";
        PreparedStatement pre = JDBCUtil.pre(con, sql);
        pre.setObject(1,3);

        int i = JDBCUtil.preExe(pre);
        System.out.println("i = " + i);

        JDBCUtil.close(pre,con);
    }

    @Test
    public void fa4() throws SQLException {
        Connection con = JDBCUtil.getCon();
        String sql = "insert into actor values(?,?,?,?,?)";
        PreparedStatement pre = JDBCUtil.pre(con, sql);
        int i = JDBCUtil.preExe(pre, null, "王五", "女", new Date(), "15631823420");

        System.out.println("i = " + i);

        JDBCUtil.close(pre,con);
    }

    @Test
    public void fa5() throws SQLException {
        Connection con = JDBCUtil.getCon();
        String sql = "select * from actor where id = ?";
        PreparedStatement pre = JDBCUtil.pre(con, sql);
        pre.setObject(1, 1);
        Object o = JDBCUtil.preQuery(pre);

        JDBCUtil.close(pre,con);
    }

    @Test
    public void fa6() throws SQLException {
        Connection con = JDBCUtil.getCon();
        String sql = "select * from actor";
        PreparedStatement ps = JDBCUtil.pre(con, sql);
        Object o = JDBCUtil.preQuery(ps);
        JDBCUtil.close(ps,con);
    }
}
